//用户扩展控件，可拖动
Ext.ux.PanelFieldDragZone = Ext.extend(Ext.dd.DragZone, {
    constructor: function(){},

    init: function(panel) {
        if (panel.nodeType) {
            Ext.ux.PanelFieldDragZone.superclass.init.apply(this, arguments);
        } else {
            if (panel.rendered) {
                Ext.ux.PanelFieldDragZone.superclass.constructor.call(this, panel.getEl());
                var i = Ext.fly(panel.getEl()).select('label');
                i.unselectable();
            } else {
                panel.on('afterlayout', this.init, this, {single: true});
            }
        }
    },

    scroll: false,

    getDragData: function(e) {
        var t = e.getTarget('label');
        if (t) {
            e.stopEvent();
            if (Ext.isOpera) {
                Ext.fly(t).on('mousemove', function(e1){
                    t.style.visibility = 'hidden';
                    (function(){
                        t.style.visibility = '';
                    }).defer(1);
                }, null, {single:true});
            }

            var f = Ext.getCmp(t.id);
            var d = document.createElement('div');
            d.className = 'x-form-text';
            d.appendChild(document.createTextNode("创建新对象"));
            Ext.fly(d).setWidth(f.getEl().getWidth());
            return {
                field: f,
                ddel: d
            };
        }
    },

    getRepairXY: function() {
        return this.dragData.field.getEl().getXY();
    }
});

Ext.ux.CellFieldDropZone = Ext.extend(Ext.dd.DropZone, {
    constructor: function(ppform){this.ppform = ppform;},

    init: function(panel) {
        if (panel.rendered) {
            this.panel = panel;
            this.El = panel.getEl();
            Ext.ux.CellFieldDropZone.superclass.constructor.call(this, this.El);
        } else {
            panel.on('render', this.init, this);
        }
    },
    
    containerScroll: true,
    
    getTargetFromEvent: function(e) {
        return {
        		form:Ext.getCmp("_newform_id")
        	};
    },
    
    onNodeEnter: function(target, dd, e, dragData) {
        delete this.dropOK;
        if (!target) {
            return;
        }
        var f = dragData.field;
        if (!f) {
            return;
        }
        this.dropOK = true;
    },

    onNodeOver: function(target, dd, e, dragData) {
        return this.dropOK ? this.dropAllowed : this.dropNotAllowed;
    },

    onNodeOut: function(target, dd, e, dragData) {
    },

    onNodeDrop: function(target, dd, e, dragData) {
    	//if(mulSelectItem.length!=0){	
			//dragresize.deselect(true,e);
		//}
    	
    	
    	//for(var i=0;i<this.ppform.mulSelectItemId.length;i++)
    			//alert(this.ppform.mulSelectItemId[i]);
        if (this.dropOK) {
        	var  formId_Tab_no = "_newform_id";
        	if(this.ppform.useFormTab.flag)
        		formId_Tab_no = (Ext.getCmp("TabsPanel_cfz_pp").getActiveTab().get(0).getId());
    		var xx = e.getXY()[0]-Ext.getCmp(formId_Tab_no).getPosition()[0];
            var yy = e.getXY()[1]-Ext.getCmp(formId_Tab_no).getPosition()[1];
            
//            var iii = "";
//            for(var i in this.ppform)
//            	iii = iii + i +'  ';
//            alert(iii);
            //
    		if(this.ppform.mulSelectItemId.length!=0){	
    			mourseMoveObject.isCanSelect = true;
    			moveobjectcfz.deselect(true,e);
			}
			if(this.ppform.centerPanel.items.length == 0){
				alert("请先建立表单");
				return;
            }
        	var tempId = dragData.field.id+this.ppform.itemIndex;
        	var codeId = "code"+this.ppform.itemTabIndex;
        	this.ppform.itemIndex++;
            var type = dragData.field.itemtype;
            var createJson = eval("this.ppform.allTypeItem."+type);
            var useType = eval("this.ppform.allItemProperty.useType"+type);
          //  var width = eval("this.ppform.allTypeItem."+type+".i_width");
           // var height = eval("this.ppform.allTypeItem."+type+".i_height");
          //  var src = eval("this.ppform.allTypeItem."+type+".src");
            for(var tt in eval("this.ppform.allTypeItem."+type))
            {
            	switch(tt)
            	{
            		case "i_id":
            			(eval("createJson.i_id = '"+tempId+"'"));
            			break;
            		case "i_code":
            			(eval("createJson.i_code = '"+codeId+"'"));
            			break;
            		case "i_x":
            			(eval("createJson.i_x = '"+xx+"'"));
            			break;
            		case "i_y":
            			(eval("createJson.i_y = '"+yy+"'"));
            			break;
            		case "i_tabseq":
            			(eval("createJson.i_tabseq = '"+this.ppform.itemTabIndex+"'"));
            			this.ppform.itemTabIndex++;
            			break;
            		default:
            			break;
            	}
            }
           if(eval("this.ppform.allItemProperty.useType."+type)=="noId")
           {
        	   for(var k=0;k< createJson.i_items.length;k++)
        		   createJson.i_items[k].name = codeId;
        	  
           }
            var returnFlag = true;
            if(this.ppform.linstenersFlag.beforeCreateFlag == true)
    		{
            	returnFlag = this.ppform.linsteners.beforeCreate(tempId,type,eval("this.ppform.allItemProperty.useType."+type));
    		}
            if(returnFlag==false) return;
            this.ppform.createOtherItem_byclick(createJson,"this.windowPanel",true); //是text,textarea,datapick
            return true;
        }
    }
});

